package com.stu.demo0519.demo1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 姚东名
 * Date: 2024-05-19
 * Time: 22:17
 */
public class Animal {
    public String name;//名字
    public int age;//年龄

    //成员方法：
    //1.静态代码块
    static {
        System.out.println("static :: Animal{ }");
    }
    //2.实例代码块：
    {
        System.out.println("实例代码块 Animal{ }");
    }
    //3.构造代码块（构造方法：）
    public Animal(String name, int age) {//1.调用父类的构造方法
        this.name = name;
        this.age = age;
        System.out.println("Animal()……");
    }
    public Animal() {//2.调用了父类的构造方法
        this.name = name;
        this.age = age;
    }
    //普通方法：
    public void eat() {
        System.out.println(this.name+" 正在吃饭……");
    }
    //地址转字符串

    @Override
    public String toString() {
        return "Animal{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
